package demo6;

/**
 * Created with IntelliJ IDEA.
 * Description:Comparable接口
 * User: 86183
 */
public class Student implements Comparable<Student>{
    @Override
    public int compareTo(Student o) {
        /*return this.name.compareTo(o.name);*/
        /*if (this.age > o.age){
            return 1;
        }else if(this.age <o.age){
            return -1;
        }else {
            return 0;
        }*/
        return this.age - o.age;
    }
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }



}
